/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.l4.app.main;

import com.l4.app.ui.LogPanel;
import com.l4.app.ui.TrafficLight;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextArea;

/**
 *
 * @author Thusira
 */
public class Timer extends Thread {

    private int trafficGlobalTimer = 0;
    private List<Integer> list1;
    private List<Double> list2;

    public Timer(List list) {
        this.list1 = list;
    }

    public Timer(List<Integer> passList, List<Double> passValueList) {
        this.list1 = passList;
        this.list2 = passValueList;
    }

    @Override
    public void run() {

        try {
            boolean found = false;
            while (true) {
                ++trafficGlobalTimer;
                LogPanel.counter.setText(""+trafficGlobalTimer);
                for (int i = 0; i < list1.size(); i++) {

                    if (list1.get(i) == trafficGlobalTimer) {
                        //found = true;
                        System.out.println("match found@--" + trafficGlobalTimer);
                        LogPanel.logArea.append("- High Crowd density detected at - " + trafficGlobalTimer + " sec.\n");
                        TrafficLight.isDelayApplied = true;
                        if (list2.get(i) > 80.0) {
                            TrafficLight.addedTime = 7;

                        } else if (list2.get(i) > 50.0) {
                            TrafficLight.addedTime = 4;
                            //LogPanel.logArea.append("- Pedestrian clearence time added:- 4 sec.\n\n");
                        }
                        else {
                            TrafficLight.addedTime = 0;
                        }

                    }
                }
                sleep(1000);
            }

        } catch (InterruptedException ex) {
            Logger.getLogger(Timer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
